#ifndef __DRV_LCD_H_
#define __DRV_LCD_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include "system.h"


/* Color definitions, RGB565 format */
#define LCD_COLOR_BLACK       0x0000
#define LCD_COLOR_WHITE       0xFFFF
#define LCD_COLOR_RED         0xF800
#define LCD_COLOR_GREEN       0x07E0
#define LCD_COLOR_BLUE        0x001F

#define LCD_COLOR_NAVY        0x000F
#define LCD_COLOR_DARKGREEN   0x03E0
#define LCD_COLOR_DARKCYAN    0x03EF
#define LCD_COLOR_MAROON      0x7800
#define LCD_COLOR_PURPLE      0x780F
#define LCD_COLOR_OLIVE       0x7BE0
#define LCD_COLOR_LIGHTGREY   0xC618
#define LCD_COLOR_DARKGREY    0x7BEF
#define LCD_COLOR_CYAN        0x07FF
#define LCD_COLOR_MAGENTA     0xF81F
#define LCD_COLOR_YELLOW      0xFFE0
#define LCD_COLOR_ORANGE      0xFD20
#define LCD_COLOR_GREENYELLOW 0xAFE5
#define LCD_COLOR_PINK        0xF81F
#define LCD_COLOR_SILVER      0xC618
#define LCD_COLOR_GRAY        0x8410
#define LCD_COLOR_LIME        0x07E0
#define LCD_COLOR_TEAL        0x0410
#define LCD_COLOR_FUCHSIA     0xF81F


typedef uint16_t lcd_color_t;

typedef enum {
    LCD_DIR_LRTB = 0,   // 左到右，上到下
    LCD_DIR_LRBT,       // 左到右，下到上
    LCD_DIR_RLTB,       // 右到左，上到下
    LCD_DIR_RLBT,       // 右到左，下到上
    LCD_DIR_TBLR,       // 上到下，左到右 
    LCD_DIR_BTLR,       // 下到上，左到右 
    LCD_DIR_TBRL,       // 上到下，右到左 
    LCD_DIR_BTRL,       // 下到上，右到左 
    LCD_DIR_MAX,
} _drv_lcd_dir_t;

typedef struct
{
    uint16_t width;
    uint16_t height;
    _drv_lcd_dir_t dir;
    const char *name;
} _drv_lcd_info_t;


typedef struct {

    int (*init)(void);
    int (*deinit)(void);

    int (*set_backlight)(uint8_t val);
    int (*set_direction)(_drv_lcd_dir_t dir);

    int (*set_window)(uint16_t posx, uint16_t posy, uint16_t width, uint16_t height);
    int (*draw_pixel)(uint16_t posx, uint16_t posy, lcd_color_t color);
    int (*fill_color)(uint16_t posx, uint16_t posy, uint16_t width, uint16_t height, lcd_color_t color);
    int (*fill_bitmap)(uint16_t posx, uint16_t posy, uint16_t width, uint16_t height, lcd_color_t *bitmap);
    int (*fill_bitmap_area)(uint16_t posx0, uint16_t posy0, uint16_t posx1, uint16_t posy1, lcd_color_t *bitmap);

    int (*get_info)(_drv_lcd_info_t *info);

} _drv_lcd_opt_t;



/* export func */

int drv_lcd_init(void);
int drv_lcd_deinit(void);

int drv_lcd_backlight_on(void);
int drv_lcd_backlight_off(void);
int drv_lcd_set_direction(_drv_lcd_dir_t dir);
int drv_lcd_set_window(uint16_t posx, uint16_t posy, uint16_t width, uint16_t height);
int drv_lcd_draw_pixel(uint16_t posx, uint16_t posy, lcd_color_t color);

int drv_lcd_fill_color(uint16_t posx, uint16_t posy, uint16_t width, uint16_t height, lcd_color_t color);
int drv_lcd_fill_bitmap(uint16_t posx, uint16_t posy, uint16_t width, uint16_t height, lcd_color_t *bitmap);
int drv_lcd_fill_bitmap_area(uint16_t posx0, uint16_t posy0, uint16_t posx1, uint16_t posy1, lcd_color_t *bitmap);
int drv_lcd_clear(lcd_color_t color);

int drv_lcd_get_info(_drv_lcd_info_t *info);



#ifdef __cplusplus
}
#endif

#endif // __DRV_LCD_H_
